
#include <QApplication>
#include <QLocale>
#include <QTranslator>
#include <QStyleFactory>
#include "./widgets/loginWidget/loginwidget.h"
#include "./widgets/mainWindow/mainwindow.h"
#include "entities/messageentities.h"
#include <QDir>

int main(int argc, char *argv[])
{
    // 注册自定义类型
    qRegisterMetaType<LoginRequestMessage>("LoginRequestMessage");
    qRegisterMetaType<LoginResponseMessage>("LoginResponseMessage");
    qRegisterMetaType<RegisterRequestMessage>("RegisterRequestMessage");
    qRegisterMetaType<RegisterResponseMessage>("RegisterResponseMessage");
    qRegisterMetaType<LogoutRequestMessage>("LogoutRequestMessage");
    qRegisterMetaType<LogoutResponseMessage>("LogoutResponseMessage");
    qRegisterMetaType<SearchUserRequestMessage>("SearchUserRequestMessage");
    qRegisterMetaType<SearchUserResponseMessage>("SearchUserResponseMessage");
    qRegisterMetaType<ApplyFriendRequestMessageToServer>("ApplyFriendRequestMessageToServer");
    qRegisterMetaType<ApplyFriendRequestMessageToClient>("ApplyFriendRequestMessageToClient");
    qRegisterMetaType<ApplyFriendResponseMessageToServer>("ApplyFriendResponseMessageToServer");
    qRegisterMetaType<ApplyFriendResponseMessageToClient>("ApplyFriendResponseMessageToClient");
    qRegisterMetaType<GetApplicationFromServer>("GetApplicationFromServer");
    qRegisterMetaType<GetApplicationResultFromServer>("GetApplicationResultFromServer");
    qRegisterMetaType<RequestBufferDataMessage>("RequestBufferDataMessage");
    qRegisterMetaType<ChatMessageToServer>("ChatMessageToServer");
    qRegisterMetaType<ChatMessageToClient>("ChatMessageToClient");
    qRegisterMetaType<GetChatMessageFromServer>("GetChatMessageFromServer");

    qRegisterMetaType<VideoRequestToServer>("VideoRequestToServer");
    qRegisterMetaType<VideoRequestToClient>("VideoRequestToClient");
    qRegisterMetaType<VideoResponseToServer>("VideoResponseToServer");
    qRegisterMetaType<VideoRequestToClient>("VideoRequestToClient");
    qRegisterMetaType<VideoCallFinished>("VideoCallFinished");



    // 注册QVector<QString>为元类型(处理json数据时用到)
    qRegisterMetaType<QVector<QString>>("QVector<QString>");

    QApplication a(argc, argv);
    // a.setStyle("Fusion");  // 让 QSS 更好地生效
    // 加载全局样式
    QFile file(":/style/global.qss");
    if (file.open(QFile::ReadOnly)) {
        QString styleSheet = file.readAll();
        // 直接给 QApplication 设置
        a.setStyleSheet(styleSheet);
        file.close();
    }

    QTranslator translator;
    const QStringList uiLanguages = QLocale::system().uiLanguages();
    for (const QString &locale : uiLanguages) {
        const QString baseName = "XyChatClient_" + QLocale(locale).name();
        if (translator.load(":/i18n/" + baseName)) {
            a.installTranslator(&translator);
            // a.removeTranslator(&translator);
            break;
        }
    }

    LoginWidget w;
    w.show();
    // MainWindow w;
    // w.show();
    return a.exec();
}
